package com.shengcheng.controller;

import com.shengcheng.entity.OrderInfo;
import com.shengcheng.entity.UserInfo;
import com.shengcheng.login.TingShuLogin;
import com.shengcheng.result.RetVal;
import com.shengcheng.service.OrderInfoService;
import com.shengcheng.vo.OrderInfoVo;
import com.shengcheng.vo.TradeVo;
import com.shengcheng.vo.UserInfoVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 订单信息 前端控制器
 * </p>
 *
 * @author 强哥
 * @since 2023-12-15
 */
@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order/orderInfo")
public class OrderController {
    @Autowired
    private OrderInfoService orderInfoService;

    @Operation(summary = "确认订单")
    @PostMapping("confirmOrder")
    @TingShuLogin
    public RetVal confirmOrder(@RequestBody TradeVo tradeVo) {
        OrderInfoVo orderInfoVo = orderInfoService.confirmOrder(tradeVo);
        return RetVal.ok(orderInfoVo);
    }

    //订单模块 登录模块 专辑详情
    @TingShuLogin
    @Operation(summary = "提交订单")
    @PostMapping("submitOrder")
    public RetVal submitOrder(@RequestBody OrderInfoVo orderInfoVo) {
        Map<String, Object> retMap = orderInfoService.submitOrder(orderInfoVo);
        return RetVal.ok(retMap);
    }

    //订单模块 登录模块 专辑详情 数据校验
    @Operation(summary = "校验测试")
    @PostMapping("mySubmitOrder")
    public void mySubmitOrder(@RequestBody @Valid OrderInfo orderInfo) {
        System.out.println(orderInfo);
    }

    @Operation(summary = "根据订单号获取订单信息")
    @GetMapping("getOrderInfo/{orderNo}")
    public RetVal<OrderInfo> getOrderInfo(@PathVariable String orderNo) {
        OrderInfo orderAndDetail = orderInfoService.getOrderAndDetail(orderNo);
        return RetVal.ok(orderAndDetail);
    }

}
